﻿var controller = this.lookupController();
var status = controller.analysis().status;

var purStore = ref.ExpenseType.getValue() == '4' ? ref.datagrid7.getStore() : ref.datagrid2.getStore();

if (status == 'launch' || status == 'resubmit') {
    var records = store.getModifiedRecords();

    if (records.length) {
        var dssArr = [];
        Ext.each(records, function (currentRecord, index) {
            if (currentRecord.modified) {
                var dataList = purStore.data.filterBy(function (record) {
                    return record.get('DescriptionOfSuppliesServices') == currentRecord.get('DescriptionOfSuppliesServices');
                });

                if (dataList.length) {

                    var arr = [];
                    Ext.each(dataList.items, function (o) {
                        arr.push(o.get('TotalPrice'));
                    });

                    currentRecord.set('originalAmount', arr.reduce(function (a, b) {
                        return a + b;
                    }));
                }
            }
        });
    }
}